const db = require('../db/index')


// 发布文章
exports.publishArticle = (req, res) => {
    let article = req.body
    const sql = `INSERT INTO publish (title, content, time, type,areas,authorId)
    VALUES (?, ?, ?, ?, ?, ?)`
    db.query(sql, [article.title,article.content,article.time,article.type,article.areas,req.user.id], function (err, results) {
        // 执行 SQL 语句失败
        if (err) return res.cc(err)
        return res.send({
            status: 0,
            message: '发布成功！'
        })
    })

}

//获取所有文章
exports.getAllPublish=(req,res)=>{
    const sql=`select * from publish where type=?`
    db.query(sql, req.query.type, (err, results) => {
        if (err) return res.cc(err)

        // console.log(results)
        return res.send({
            status: 0,
            message: '获取成功！',
            data:results
        })
    })
}